package actions;

//import persistence.BlogMapper;
import service.BlogService;
import service.UserServiceImpl;
import speed.mvc.action.BaseAction;
import speed.mvc.annotations.Path;

/**
 * @author zhaohaolin(zhaohaolin2010@gmail.com)
 */
@Path("/hello")
public class HelloAction extends BaseAction {

	// TODO WARN 此变量不是线程安全的
	private static int count = 0;

	@Path("/index.htm")
	public static String index() {
		count++;
		System.out.println("count=" + count);
		System.out.println(request.getRequestedSessionId());
		addModel("theList", UserServiceImpl.getUsers());
		addModel("user", UserServiceImpl.getUser(1));
		return redirect("/hello/blog.htm");
	}

	public static String blog() {
		int id = getInt("id", 0);
		// 下面的代码是从业务逻辑层接口取数据的操作
		// BlogService service = getService(BlogService.class);
		addModel("blog", service.selectBlog(id));

		// 下面的代码是直接从Mapper接口取数据,对于简单的CRUD操作非常有用
		// BlogMapper mapper = getMapper(BlogMapper.class);
		// addModel("blog", mapper.selectBlog(1));
		return forward("blog");
	}

	private static BlogService service = getService(BlogService.class);

}
